import unittest, requests
import random
import logging
from common.read_json_util import assert_api, read_json
import app
from api.p2pApi import LoginApi
from parameterized import parameterized


class TestLogin(unittest.TestCase):
    def setUp(self) -> None:
        self.login_api = LoginApi()
        self.session = requests.session()

    def tearDown(self) -> None:
        self.session.close()
# 获取图片的参数化
#     @parameterized.expand(read_json("img.json"))
#     def test01_img_parmeter(self, desc, type, status_code):
#         if type == "decimal":
#             r = random.random()
#         elif type == "interger":
#             r = random.randint(1000, 99999)
#         elif type == "kong":
#             r = ""
#         elif type == "charactor":
#             r = "".join(random.sample("shwdyehuwjis", 8))
#         else:
#             print("输入参数错误")
#             # 调用api接口用参数名代替参数
#         response = self.login_api.get_img_code(self.session, r)
#         logging.info("打印返回结果{}".format(response))
#         # 断言,打印日志可以在输出台看到结果
#         self.assertEqual(status_code, response.status_code)
# # 注册的参数化
#    @parameterized.expand(read_json("register.json"))
#    def test10_register(self,title,phone,password,verifycode,phone_code,dy_server,invite_phone,status_code,status,description):
#         r = random.random()
#         response1 = self.login_api.get_img_code(self.session,r)
#         print("图片的请求",response1)
#         response2 = self.login_api.get_sms_code(self.session,phone,app.img_code)
#         print("短信的请求",response2.request.body)
#         response3 = self.login_api.register_api(self.session,phone,password,verifycode,phone_code,dy_server,invite_phone)
#         print("注册:",response3.request.body)
#         logging.info("register response ={}".format(response3.json()))
#         assert_api(self,response3,status_code,status,description)

    @parameterized.expand(read_json("real_name.json"))
    def test_real_name(self,real_name,card_id):
        response = self.login_api.login_api(self.session,app.phone2,app.pwd)
        logging.info("response={}".format(response.status_code))
        # assert_api(self,response,200,200,"登录成功")
        response2 = self.login_api.real_name_api(self.session,real_name,card_id)
        logging.info("real_name response ={}".format(response2.json()))
        print((response2.json()))
        assert_api(self, response2, status_code, status, description)

if __name__ == '__main__':
    unittest.main()


